package com.trade.task;


import com.trade.websocket.WebSocketServer;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 *
 */
//@Component
public class WebSocketTask {
    //@Autowired
    private WebSocketServer webSocketServer;
    /**
     * 通过WebSocket每隔5秒向客户端发送消息 群发
     */
    @Scheduled(cron = "0/5 * * * * ?")
    public void sendMessageToClient() {

          webSocketServer.sendToAllClient("这是来自服务端的消息：" + DateTimeFormatter.ofPattern("HH:mm:ss").format(LocalDateTime.now()));
    }
}
